﻿myApp.controller("TenancyController", function ($scope, $http, $modal, modalService, $routeParams, $location, $filter,$compile, NgMap) {
    document.title = "Penang Realty 世界地產 Tenancy Calculator";
    $scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 Tenancy Calculator', 'description': 'Free online tenancy calculator. Try it now.' });
    $scope.calculate = function () {
        // http://expatriateadvisory.com/guide-in-renting-a-property-in-malaysia/
        var rentalTotal = $scope.rentalPrice * 12 * $scope.tenancyPeriod;
        $scope.stampDuty = (rentalTotal - 2400) / 250 * stampDutyRate($scope.tenancyPeriod);
        if ($scope.tenancyPeriod < 4) {
            if ($scope.rentalPrice < 10000)
                $scope.tenancyCharges = $scope.rentalPrice * 0.25;
            else 
                $scope.tenancyCharges = 10000 * 0.25 +  ($scope.rentalPrice-10000) * 0.20;
         }
        else
        {
            if ($scope.rentalPrice < 10000)
                $scope.tenancyCharges = $scope.rentalPrice * 0.50;
            else
                $scope.tenancyCharges = 10000 * 0.50 + ($scope.rentalPrice - 10000) * 0.20;

        }
        $scope.total = $scope.tenancyCharges + $scope.stampDuty + ($scope.addionalCopy * 19)
    }
    function stampDutyRate(year) {
        if (year < 2)
            return 1;
        else if (year < 3)
            return 2;
        else
            return 3;

    }
})